<?php
  require '../db.func.php';
  require  '../tools.func.php'; 
  if(!empty($_POST['adminuser'])){
      $adminuser=$_POST['adminuser'];
      $adminpass=$_POST['adminpass'];
      $prefix=getprefix();
      $sql="SELECT id, adminuser FROM {$prefix}admin WHERE adminuser='$adminuser' AND adminpass='$adminpass' ";
      $r=queryone($sql);
      //判断为true flase  实际是个数组  有值
      if($r){
          setsession('admin',['adminuser'=>$adminuser, 'id'=>$r['id']]);
          $login_at=date('Y-m-d  H:i:s');

          $ip=$_SERVER['REMOTE_ADDR']=='::1'?'127.0.0.1':$_SERVER['REMOTE_ADDR'];
          $login_ip=ip2long($ip);
          $s="UPDATE {$prefix}admin SET login_ip='$login_ip' , login_at='$login_at' WHERE id='{$r['id']}'";
          // 当有这种ID= $r['id']  要加‘{}’
          execute($s);

          header('location:index.php');
      }
      else{
         setinfo('用户名或者密码错误');
      }  
    



  }




?>
<!doctype html>

<html>

<head>
  <title>慕课商城</title>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <!--     Fonts and icons     -->
  <link rel="stylesheet" type="text/css" href="assets/css/googlefonts.css?family=Roboto:300,400,500,700|Roboto+Slab:400,700|Material+Icons" />
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">
  <!-- Material Kit CSS -->
  <link href="assets/css/material-dashboard.css?v=2.1.1" rel="stylesheet" />
</head>

<body>
  <div class="wrapper ">
    <div>
      <div>
        <div class="container" style="width: 50%;margin-top: 250px;">
          <div class="row">
            <div class="col-md-12">
              <div class="col-md-12">
                <div class="card">
               
                  <div class="card-header card-header-primary">
                    <h4 class="card-title">登录</h4>
                    <p class="card-category">以管理员身份登录后台</p>
                  </div>
                  <div class="card-body">
                    <p>
                              <?php
                              if (hasinfo()) echo getinfo();
                              ?>
                    </p>
                    <form  action="login.php" method="post">
                      <div class="row">
                        <div class="col-md-12">
                          <div class="form-group">
                         
                            <label class="bmd-label-floating">用户名</label>
                            <input type="text"   name="adminuser" class="form-control">
                          </div>
                        </div>
                      </div>
                      <div class="row">
                        <div class="col-md-12">
                          <div class="form-group">
                            <label class="bmd-label-floating">密码</label>
                            <input type="password"  name="adminpass" class="form-control">
                          </div>
                        </div>
                      </div>
                      <button type="submit" class="btn btn-primary pull-right">登录</button>
                      <div class="clearfix"></div>
                    </form>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <script src="assets/js/core/jquery.min.js"></script>
  <script src="assets/js/core/popper.min.js"></script>
  <script src="assets/js/core/bootstrap-material-design.min.js"></script>
</body>

</html>